<%--
  Created by IntelliJ IDEA.
  User: yutong
  Date: 14-4-24
  Time: 上午11:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <%@include file="../includes/common.jsp" %>
    <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
    <%@ page contentType="text/html;charset=UTF-8" %>

    <link rel="stylesheet" type="text/css"  href="<c:url value='/js/css/spigPet.css'/>"/>
    <title>用户注册</title>
</head>
<body>
<div style="text-align: center">

<div id="tabDiv" >
    用户名：<input type="text" id="loginName" name="loginName" >
</div>
<div>
    密码：<input type="password" id="password" name="password">
</div>
<div>
    确认密码：<input type="password" id="surePassword" name="surePassword">
</div>

<div> 性别：
    男<input type="radio" name="sex" value="0">
    女<input type="radio" name="sex" value="1">
    保密<input type="radio" name="sex" value="2" checked="checked">
</div>
<div>
    生日： <input type="text"  data-date-format="yyyy-mm-dd" id="birthday" name="birthday" onclick="getBirthday()" readonly="readonly">
</div>
<div>
    邮箱：<input type="text" id="email" name="email">
</div>
<div id="city_1" class="demo">
    城市：
    <select class="prov" id="prov" onchange="getProv()"></select>
    <select class="city" disabled="disabled" id="citys" onchange="getCity()"></select>
    <input type="hidden" id="city" name="city">
</div>
    <br>
<div>
        验证码：
        <input type="text" value="" name="imageCode" id="imageCode" width="30" height="22"
        style="padding-top: 1px;">
    &nbsp;<img name="randImage" id="randImage" width="80" height="22" style="margin-bottom: -3px" src="tourist/showImage"/>
    &nbsp; <a onclick="reloadValidate()">换一张</a>
</div>
    <br/><br/>
<div class="controls">
    <input type="button" id="saves" class="btn btn-primary" onclick="save()"
           value="保存"/>
    <input type="button" onclick="quit()" class="btn btn-primary"
           value="取消"/>
</div>
    <label>已有账号，直接<a id="login"  href="">登录</a></label>
</div>

</body>
</html>
<script type="text/javascript" src="<c:url value="/js/jquery.cityselect.js" />"></script>
<script type="text/javascript">
    var rules = {
        objInfo: {
            loginName: {
                checkEmpty: ["loginName", "用户名 "],
                ajax: [basePath + "admin/user/checkRepeatLoginName", {}, {loginName: "$('#loginName').val().trim()",oldName:"''"},
                    backFunc, "text", "POST"]
            },
            password: {
                checkEmpty: ["password", "密码"],
                checkRegExp: ["password", "密码", JCRegExp.letterNum],
                min: ["password", "3", "密码长度"]
            },
            surePassword: {
                checkEmpty: ["surePassword", "确认密码"]
            },
            birthday: {
                checkEmpty: ["birthday", "生日"]
            },
            email: {
                checkEmpty: ["email", "邮箱"]
            },
            city: {
                checkEmpty: ["prov", "城市"]
            },
            imageCode: {
                checkEmpty: ["imageCode", "验证码"],
                ajax: [basePath + "admin/user/checkRepeatImageCode", {}, {imageCode: "$('#imageCode').val().trim()"},
                    backCode, "text", "POST"]
            }

        }
    };
    function backFunc(data, returnObj) {
        returnObj.obj = $('#loginName');
        returnObj.errMsg = "用户名已存在！";
        if (data == "true") {
            returnObj.bool = true;
        }
        if (data == "false") {
            returnObj.bool = false;
        }
        return returnObj;
    }
    function backCode(data, returnObj) {
        returnObj.obj = $('#imageCode');
        returnObj.errMsg = "验证码不正确！";
        if (data == "true") {
            returnObj.bool = true;
        }
        if (data == "false") {
            returnObj.bool = false;
        }
        return returnObj;
    }
    function surePass(){
        var password=$("#password").val().trim();
        var surePassword=$("#surePassword").val().trim();
        return password!=surePassword;
    }

    $(function(){
        $("#city_1").citySelect({
            nodata:"none",
            required:false
        });
    });

    function reloadValidate(){
        $("#randImage").attr("src",basePath+"tourist/showImage?_="+Math.random());
    }

    var today = new Date().dateFormat();
    var dateConf = {
        language: 'zh-CN',
        endDate: today,
        weekStart: 1,
        todayBtn: true,
        autoClose: true,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    };
    function getBirthday(){
        $("#birthday").datetimepicker(dateConf);
        autoComplete();
        JC.inputInit();
    }

    function save() {
        if(!JC.validate(rules)) return;
        $("#saves").button('loading');
        if(surePass()){
            alert("两次密码不一致！");
        }else{
            $.ajax({
                url: basePath + "tourist/addUser",
                data: {
                    loginName: $("#loginName").val().trim(),
                    password: $("#password").val().trim().md5(),
                    sex: $("input[name=sex]:checked").val(),
                    birthday:$("#birthday").val().trim(),
                    email:$("#email").val().trim(),
                    city:$("#city").val().trim()
                },
                dataType: "json",
                type: "POST",
                success: function () {
                    $.messager.alert("提示", "注册成功！", "", function () {
                        parent.$("#dataEdit").dialog('close');

                    });
                },
                error: doError
            })
        }
    }
    function getCity(){
        $("#city").attr("value", $("#prov").val()+","+ $("#citys").val());
    }
    function getProv(){
        $("#city").attr("value","");
        $("#city").attr("value", $("#prov").val());
    }
    function quit() {
        parent.$("#dataEdit").dialog('close');
    }
</script>